package
entities{
	import com.adobe.utils.PerspectiveMatrix3D;

	import flash.display3D.Context3D;
	import flash.geom.Matrix3D;
	/**
	 * @author perry
	 */
	public class MicroGZMCamera extends MicroGZMEntity
	{
		private var _projectionmatrix:PerspectiveMatrix3D = new PerspectiveMatrix3D();
		
		private var _viewWidth:Number = 640;
		private var _viewHeight:Number = 480;
		private var fov:Number = 45;
		private var _zNear:Number = 0.01;
		private var _zFar:Number = 10000;

		public function MicroGZMCamera( contextIn:Context3D, fieldOfView:Number = 0,
										vWidth:Number = 0, vHeight:Number = 0,
										zNear:Number = 0, zFar:Number = 0 )
		{
			transform = new Matrix3D();
			context = contextIn;
			
			if( fieldOfView != 0 ) fov = fieldOfView;
			if( vWidth != 0 ) _viewWidth = vWidth;
			if( vHeight != 0 ) _viewHeight = vHeight;
			if( zNear != 0 ) _zNear = zNear;
			if( zFar != 0 ) _zFar = zFar;
			
			updateValues();
		}
		
		private function updateValues():void
		{
			_projectionmatrix.identity();
			_projectionmatrix.perspectiveFieldOfViewRH( fov, _viewWidth / _viewHeight, _zNear, _zFar );
		}
		
		public function get FOV():Number
		{
			return fov;
		}
		
		public function set FOV( val:Number ):void
		{
			fov = val;
			
			updateValues();
		}
		
		public function get viewWidth():Number
		{
			return _viewWidth;
		}
		
		public function set viewWidth( val:Number ):void
		{
			_viewWidth = val;
			
			updateValues();
		}
		
		public function get viewHeight():Number
		{
			return _viewHeight;
		}
		
		public function set viewHeight( val:Number ):void
		{
			_viewHeight = val;
			
			updateValues();
		}
		
		public function get zNear():Number
		{
			return _zNear;
		}
		
		public function set zNear( val:Number ):void
		{
			_zNear = val;
			
			updateValues();
		}
		
		public function get zFar():Number
		{
			return _zFar;
		}
		
		public function set zFar( val:Number ):void
		{
			_zFar = val;
			
			updateValues();
		}
		
		public function get projectionmatrix():PerspectiveMatrix3D
		{
			return _projectionmatrix;
		}
		
		public function set projectionmatrix( val:PerspectiveMatrix3D ):void
		{
			_projectionmatrix = val;
		}
	}
}
